#include "baseutil.h"
#include <math.h>

#include "Log.h"
#include "String.h"

using namespace std;

namespace yet{

Logger& operator <<(Logger& slog, const String& s) {
	slog.Append(string(s.buffer(), s.length()));
	return slog;
}

WithTag::WithTag() :
		tag(0) {

}
void WithTag::setTag(int tag_) {
	tag = tag_;
}
int WithTag::getTag() {
	return tag;
}

//return value > 0 if found;
//else ~value is the insert pos.
int binarySearch(const int* a, int start, int len, int key) {
	int high = start + len, low = start - 1, guess;

	while (high - low > 1) {
		guess = (high + low) / 2;

		if (a[guess] < key)
			low = guess;
		else
			high = guess;
	}

	if (high == start + len)
		return ~(start + len);
	else if (a[high] == key)
		return high;
	else
		return ~high;
}

}
